package com.fare.taluo.core.domain.crawl;


import java.sql.Date;
import java.util.List;

import javax.persistence.Column;

import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity2;
/**
 * 抓取统计（存储持久化数据）
 * 每天，每一条航线执行后，存入一条数据
 * @author gan
*/
@javax.persistence.Table(name="FDC_CRAWL_STATISTICS")
@javax.persistence.Entity
public class FdcCrawlStatisticsEntity extends BaseEntity2<FdcCrawlStatisticsEntity> implements Entity{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Column(name="create_time")
	private Date createTime;
	
	@Column(name="from_city")
	private String fromCity;
	
	@Column(name="from_city_name")
	private String fromCityName;
	
	@Column(name="to_city")
	private String toCity;
	
	@Column(name="to_city_name")
	private String toCityName;
	
	@Column(name="data_sources")
	private Long dataSources;
	
	@Column(name="grab_date")
	private Date grabDate;
	
	@Column(name="grab_channel_id")
	private String grabChanelIdStr;
	
	@Column(name ="channel_source_data_info")
	private String channelSourceDataInfo;
	
	@Column(name="grab_channel")
	private String grabChannelName;
	
	@Column(name="hbase_key")
	private String hbaseKey;
	
	@Column(name="totalNum")
	private Integer totalNum;
	
	@Column(name="successNum")
	private Integer successNum;
	
	@Column(name="failNum")
	private Integer failNum;
	
	@Column(name ="flightDaysNum")
	private Integer flightDaysNum;
	
	@Column(name="actualFlightDayNum")	
	private Integer actualFlightDayNum;
	
	@Column(name ="flight_date_info")
	private String flightDateInfo;
	
	@Column(name = "channel_lines_info")
	private String channelLinesInfo;
	
	
	private static FdcCrawlStatisticsEntityRepository getFdcCrawlStatisticsEntityRepository(){
		return InstanceFactory.getInstance(FdcCrawlStatisticsEntityRepository.class);
	}
	
	/**
	 * 执行存入数据(持久化数据)
	 */	
	public  void saveDatas(List<FdcCrawlStatisticsEntity> entityList){
		getFdcCrawlStatisticsEntityRepository().saveDatas(entityList); 
	}
	
	/**
	 * delete by city and grabDate
	 */	
	public void deleteEntitys(String fromCity,String toCity,Date grabDate){
		getFdcCrawlStatisticsEntityRepository().deleteEntitys(fromCity, toCity, grabDate);
	}
	/**
	 * update the entity
	*/
	public void updateEntitys(List<FdcCrawlStatisticsEntity> entityList){
		getFdcCrawlStatisticsEntityRepository().updateDatas(entityList);
	}
	
	/**
	 * find FdcCrawlStatisticsEntity by grabDate
	*/
	public List<FdcCrawlStatisticsEntity> findEntity(String fromCity,String toCity,Date date1,Date date2,Date dateGrabDate){
		return getFdcCrawlStatisticsEntityRepository().findByGrabDate(fromCity,toCity,date1, date2,dateGrabDate);
	}
	
	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), id);
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}

	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public Long getDataSources() {
		return dataSources;
	}

	public void setDataSources(Long dataSources) {
		this.dataSources = dataSources;
	}

	public Date getGrabDate() {
		return grabDate;
	}

	public void setGrabDate(Date grabDate) {
		this.grabDate = grabDate;
	}

	

	public String getGrabChannelName() {
		return grabChannelName;
	}

	public void setGrabChannelName(String grabChannelName) {
		this.grabChannelName = grabChannelName;
	}

	public String getHbaseKey() {
		return hbaseKey;
	}

	public void setHbaseKey(String hbaseKey) {
		this.hbaseKey = hbaseKey;
	}

	public Integer getTotalNum() {
		return totalNum;
	}

	public void setTotalNum(Integer totalNum) {
		this.totalNum = totalNum;
	}
	
	public Integer getFlightDaysNum() {
		return flightDaysNum;
	}

	public void setFlightDaysNum(Integer flightDaysNum) {
		this.flightDaysNum = flightDaysNum;
	}

	public Integer getActualFlightDayNum() {
		return actualFlightDayNum;
	}

	public void setActualFlightDayNum(Integer actualFlightDayNum) {
		this.actualFlightDayNum = actualFlightDayNum;
	}

	public Integer getSuccessNum() {
		return successNum;
	}

	public void setSuccessNum(Integer successNum) {
		this.successNum = successNum;
	}

	public Integer getFailNum() {
		return failNum;
	}

	public void setFailNum(Integer failNum) {
		this.failNum = failNum;
	}

	public String getGrabChanelIdStr() {
		return grabChanelIdStr;
	}

	public void setGrabChanelIdStr(String grabChanelIdStr) {
		this.grabChanelIdStr = grabChanelIdStr;
	}

	public String getChannelSourceDataInfo() {
		return channelSourceDataInfo;
	}

	public void setChannelSourceDataInfo(String channelSourceDataInfo) {
		this.channelSourceDataInfo = channelSourceDataInfo;
	}

	public String getChannelLinesInfo() {
		return channelLinesInfo;
	}

	public void setChannelLinesInfo(String channelLinesInfo) {
		this.channelLinesInfo = channelLinesInfo;
	}

	public String getFlightDateInfo() {
		return flightDateInfo;
	}

	public void setFlightDateInfo(String flightDateInfo) {
		this.flightDateInfo = flightDateInfo;
	}

	
	
}
